<!-- 机构信息 -->
<template>
	<view class="container">
		<view class="c-info" v-if="isOrg">
			<image :src="baseURL + orgInfo.img" mode=""></image>
			<text>机构全称：{{orgInfo.name}}</text>
			<text>机构地址：{{orgInfo.address}}</text>
			<text>机构负责人：{{orgInfo.resp_name}}</text>
			<text>联系电话：{{orgInfo.resp_mobile}}</text>
			<text>我的职务：</text>
			<view class="c-info_util" @click="onUnbind">
				<text>解除机构关系</text>
			</view>
		</view>
		<view class="c-alert" v-else>
			<view v-if="isResume">
				<view class="">
					<u-alert title="简历已发布，请等待机构查阅" type="success" :show-icon="true"></u-alert>
				</view>
				
				<view class="alert-link">
					<text>点击前往</text>
					<text :style="{'color':'orange'}" @click="toTeacherResume">修改简历</text>
				</view>
			</view>
			<view v-else>
				<view class="">
					<u-alert title="没有发布的简历" type="warning" :show-icon="true"></u-alert>
				</view>
				<view class="alert-link">
					<text>点击前往 </text>
					<text :style="{'color':'orange'}" @click="toTeacherResume">发布简历</text>
				</view>
			</view>
			<view class="alert-list">
				<view class="alert-list-headline">
					<text>机构邀约记录</text>
				</view>
				<view class="alert-list-cell" v-if="inviteList">
					<u-cell-group>
						<u-cell v-for="item in inviteList" :key="item.id" icon="setting-fill" :title="item.organ_name" :value="item.statusValue" @click="onInvite(item)"></u-cell>
					</u-cell-group>
				</view>
			</view>
			<view class="c-empty" v-if="inviteList.length==0">
				<u-empty icon="/static/empty/list.png" text="暂无机构邀约信息" textSize="18" marginTop="25%" width="80%"></u-empty>
			</view>
		</view>
		<view class="c-module">
			<u-modal :show="unbindModal" title="操作确认" content='此操作一旦完成无法撤销,请确认是否与该机构解绑' showCancelButton
				@confirm="unbindModalConfirm" @cancel="unbindModal = false"></u-modal>
			<u-modal :show="inviteModal" title="邀请确认" content='您可以同意或接受该机构邀请,同意后将加入该机构' showCancelButton
			 :confirmText="'接受'" :cancelText="'拒绝'" 	@confirm="inviteModalConfirm" @cancel="inviteModalCancel" ></u-modal>
		</view>
	</view>
</template>

<script>
	export default {
		name: "",
		data() {
			return {
				// 机构信息
				orgInfo:null,
				// 邀请的id
				inviteId:null,
				// 邀请列表
				inviteList:null,
				// 是否发布简历
				isResume: true,
				// 是否已有机构
				isOrg: true,
				// 邀请确认模态框
				inviteModal:false,
				// 解绑确认模态框
				unbindModal: false
			}
		},
		onShow() {
			this.getTeacherOrgInfo()
		},
		methods: {
			// 获取机构信息
			getTeacherOrgInfo(){
				this.$http.getTeacherOrgInfo().then(res=>{
					this.orgInfo = res
				}).catch(err=>{
					this.isOrg = false
					this.getInviteTeacherList()
					this.getTeacherResume()
				})
			},
			// 获取老师简历
			getTeacherResume() {
				this.$http.getTeacherResume().then(res => {
					if(res){
						if(res.status==1){
							this.isResume = true
						}else{
							this.isResume = false
						}
					}else{
						this.isResume = false
					}
				})
			},
			// 点击查看邀请
			onInvite(params){
				this.inviteId = params.id
				if(params.status != 1) return
				this.inviteModal = true
			},
			// 拒绝邀请
			inviteModalCancel(){
				this.inviteModal = false
				this.$http.updateTeacherInvite({id:this.inviteId,status:3}).then(res=>{
					uni.$u.toast("您已拒绝该机构的邀请")
					this.getTeacherOrgInfo()
				}).catch(err=>{
					uni.$u.toast(err.msg)
				})
			},
			// 同意邀请
			inviteModalConfirm(){
				this.inviteModal = false
				this.$http.updateTeacherInvite({id:this.inviteId,status:2}).then(res=>{
					uni.$u.toast("恭喜您已经加入该机构")
					this.getTeacherOrgInfo()
				}).catch(err=>{
					uni.$u.toast(err.msg)
				})
			},
			// 获取机构邀请记录
			getInviteTeacherList(){
				this.$http.getInviteTeacherList().then(res=>{
					this.inviteList = res.data
					this.inviteList.forEach(item=>{
						switch (Number(item.status)){
							case 1:
								item.statusValue = "待处理"
								break;
							case 2:
								item.statusValue = "已接受"
								break;
							case 3:
								item.statusValue = "已拒绝"
								break;
						}
					})
				})
			},
			// 跳转简历页面
			toTeacherResume() {
				uni.navigateTo({
					url: "teacherResume"
				})
			},
			// 确认解绑
			unbindModalConfirm() {
				this.unbindModal = false
				this.$http.unbindOrg().then(res=>{
					uni.$u.toast("已解绑")
					this.getTeacherOrgInfo()
				}).catch(err=>{
					uni.$u.toast(err.msg)
				})
			},
			// 解绑操作
			onUnbind() {
				this.unbindModal = true
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;

		.c-info {
			width: 100%;
			display: flex;
			flex-direction: column;

			&>image {
				width: 100%;
				height: 350rpx;
				border-radius: 15rpx;
				margin-bottom: 20rpx;
			}

			&>text {
				font-size: 30rpx;
				line-height: 70rpx;
			}

			.c-info_util {
				font-size: 30rpx;
				color: red;
				padding: 40rpx 0;
				text-align: center;
			}
		}
		
		.c-alert{
			.alert-link{
				padding: 20rpx 0;
				text-align: center;
				color: #aaa;
			}
			
			.alert-list{
				margin-top: 30rpx;
				.alert-list-headline{
					font-size: 32rpx;
					font-weight: bold;
					margin-bottom: 20rpx;
				}
			}
		}
	}
</style>
